﻿using System;
using System.Linq;
using BillForMVC.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

namespace BillForMVC.Data
{
    public class SeedData
    {
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new BillForMVCContext(serviceProvider.GetRequiredService<DbContextOptions<BillForMVCContext>>()))
            {
                if (context.Bill.Any())
                {
                    return;
                }

                context.Bill.AddRange(
                    new Bill
                    {
                        Content = "测试数据1",
                        Price = 15,
                        BillDate = DateTime.Parse("2020-6-29"),
                        Category = "测试数据",
                        User = "Test"
                    }, new Bill
                    {
                        Content = "测试数据2",
                        Price = 18.2m,
                        BillDate = DateTime.Parse("2020-6-29"),
                        Category = "测试数据",
                        User = "Test"
                    }
                );
                context.SaveChanges();
            }
        }
    }
}